<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 
        参数数据解析
        1. 在注册页 写入并提交数据到登录页
        2. 登录页获取参数数据 => 解析为对象

        注意:一定要从注册页提交数据到登录页  => 直接打开登录页无数据

        ?user=zxczxc&pwd=123123&phone=17386141516&email=1272071496@qq.com
         => {user:'a123123',pwd:123123}
         
     -->

</body>
<script>
    var search = location.search;
    var data = {};

    if (search) {
        console.log(search);
        var str = search.substring(1);
        // var str = search.substr(1);
        console.log(str);

        var list = str.split("&");
        console.log(list);

        for (var i = 0; i < list.length; i++) {
            var item = list[i]; //'user=zxczxc', 'pwd=123123', 'phone=17386141516'
            var key = item.split("=")[0]; //  "user" 先将字符串用"="拆分后取第一个
            var val = item.split("=")[1]; //  "zxczxc" 先将字符串用"="拆分后取第二个
            
            data[key] = decodeURIComponent(val); // data["user"] = "zxczxc"
        }
        console.log(data);


    } else {
        if (confirm("您还没有注册,是否注册")) {
            location.href = "./register.html";
        }
    }

</script>

</html>